package com.typy.www.tpay.util;

import android.content.Context;

import com.bumptech.glide.load.data.DataFetcher;
import com.bumptech.glide.load.data.HttpUrlFetcher;
import com.bumptech.glide.load.model.GenericLoaderFactory;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.ModelLoader;
import com.bumptech.glide.load.model.ModelLoaderFactory;
import com.bumptech.glide.load.model.stream.StreamModelLoader;

import java.io.InputStream;

/**
 * Created by 13799 on 2018/7/29.
 */

public class CacheImageLoad implements StreamModelLoader<LoadImage> {

    @Override
    public DataFetcher<InputStream> getResourceFetcher(final LoadImage model, int width, int height) {
        return new HttpUrlFetcher(new GlideUrl(model.getImageUrl())) {
            @Override
            public String getId() {
                return model.getImageId();
            }
        };
    }

    public static class Factory implements ModelLoaderFactory<LoadImage, InputStream> {
        @Override
        public ModelLoader<LoadImage, InputStream> build(Context context, GenericLoaderFactory factories) {
            return new CacheImageLoad();
        }

        @Override
        public void teardown() { /* no op */ }
    }

}
